using System;
using System.ComponentModel;

namespace PickGold.Charting.Design
{
	internal class DataPointCollectionEditor : ChartCollectionEditor
	{
		public DataPointCollectionEditor()
			: base(typeof(DataPointCollection))
		{
		}

		protected override object CreateInstance(Type itemType)
		{
			if ((base.Context != null) && (base.Context.Instance != null))
			{
				if (base.Context.Instance is Series)
				{
					return new DataPoint((Series)base.Context.Instance);
				}
				if (base.Context.Instance is Array)
				{
					throw new InvalidOperationException(SR.ExceptionEditorMultipleSeriesEditiingUnsupported);
				}
			}
			return base.CreateInstance(itemType);
		}

		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			if (((context != null) && (context.Instance != null)) && !(context.Instance is Series))
			{
				throw new InvalidOperationException(SR.ExceptionEditorMultipleSeriesEditiingUnsupported);
			}
			return base.EditValue(context, provider, value);
		}
	}
}

